package com.ciei.dpagm.service.conditionRule.factMode;

import com.alibaba.fastjson.JSONObject;
import com.ciei.dpagm.common.enums.FactModeEnum;
import com.ciei.dpagm.service.conditionRule.ConditionHandleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author pp
 * @date 2023/03/17
 */
@Service
public class FactModeFactoryService {
    public static Integer oneFactModeIndex = 0;
    public static Integer twoFactModeIndex = 1;
    public static Integer threeFactModeIndex = 2;
    public static String title = "事实方式";

    /**
     * 解析
     * @param factModeList 事实方式列表
     * @param originData 源数据
     * @return
     */
    public JSONObject analysis(List<String> factModeList, JSONObject originData){
        AbstractFactModeService abstractFactModeService = getSonService(factModeList);
        if(abstractFactModeService == null){
            return ConditionHandleService.notMatchSonServiceMessage(title);
        }
        FactModeEnum twoFactModeEnum = FactModeEnum.getEnumByValue(Integer.valueOf(factModeList.get(twoFactModeIndex)));
        if(twoFactModeEnum == null){
            return ConditionHandleService.notFoundCorrespondenceMessage(twoFactModeIndex,title);
        }
        return abstractFactModeService.analysis(factModeList,originData,twoFactModeEnum);

    }
    /**
     * 解析
     * @param factModeList 事实方式列表
     * @param sonFactModeOptionDataList 子事实方式下拉框数据列表
     * @param twoFactModeEnum 第二级事实方式枚举
     * @return
     */
    public void conversionOptionList(List<String> factModeList,List<JSONObject> sonFactModeOptionDataList,FactModeEnum twoFactModeEnum){
        AbstractFactModeService abstractFactModeService = getSonService(factModeList);
        if(abstractFactModeService == null){
            return;
        }
        abstractFactModeService.conversionOptionList(factModeList,sonFactModeOptionDataList,twoFactModeEnum);
    }

    /**
     * 获取子类
     * @param factModeList
     * @return
     */
    public AbstractFactModeService getSonService(List<String> factModeList){
        AbstractFactModeService abstractFactModeService = null;
        FactModeEnum factModeEnum = FactModeEnum.getEnumByValue(Integer.valueOf(factModeList.get(0)));
        if(factModeEnum == null){
            return null;
        }
        switch (factModeEnum) {
            case ALL_KEY_NAME:
                abstractFactModeService = new AllKeyNameFactModeService();
                break;
            case KEY_VALUE_DATA_TYPE:
                abstractFactModeService = new DataTypeFactModeService();
                break;
            default:
                break;
        }
        if(abstractFactModeService == null){
            return null;
        }
        return abstractFactModeService;
    }

}
